package com.hzqy.service.activity;

import com.hzqy.persistence.dao.activity.PersonalizedActivityDao;
import com.hzqy.service.core.GenericServiceBean;
import com.hzqy.web.vo.activity.PersonalizedActivityVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

@Service
public class PersonalizedActivityServiceBean extends GenericServiceBean<PersonalizedActivityVo, PersonalizedActivityDao, Integer> {
    protected final Logger LOG = LoggerFactory.getLogger(getClass());
    @Resource
    PersonalizedActivityDao personalizedActivityDao;
    @Override
    public PersonalizedActivityDao getEntityDao() {
        return personalizedActivityDao;
    }

    public List<PersonalizedActivityVo> selectPersonalizedActivityVo(PersonalizedActivityVo vo) {
        if(vo.getF_cb_type() == 1){ // 如果是签到，需要加上本周的开始时间和结束时间
            SimpleDateFormat longSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String search_begin = longSdf.format(DateUtils.getCurrentWeekDayStartTime());// 一周的开始时间
            String search_end = longSdf.format(DateUtils.getCurrentWeekDayEndTime());//一周的结束时间
            vo.setSearch_begin_date(search_begin);
            vo.setSearch_end_date(search_end);
        }
        List<PersonalizedActivityVo> voList = personalizedActivityDao.selectPersonalizedActivityVo(vo);
        if(voList==null)
            voList = new ArrayList<PersonalizedActivityVo>();
        return voList;
    }

    /**
     * 统计每个分类下内容的点播量
     * @param vo
     * @return
     */
    public List<PersonalizedActivityVo> selectPersonalizedActivityStats(PersonalizedActivityVo vo) {
        List<PersonalizedActivityVo> voList = personalizedActivityDao.selectPersonalizedActivityStats(vo);
        if(voList==null)
            voList = new ArrayList<PersonalizedActivityVo>();
        return voList;
    }
    /**
     *
     * @param vo
     * @return
     */
    public int insertPersonalizedActivityVo(PersonalizedActivityVo vo){
        List<PersonalizedActivityVo> voList = this.selectPersonalizedActivityVo(vo);
        if(voList.size()>0){ // 大于0说明本周已经签到过
            return personalizedActivityDao.updatePersonalizedActivityVo(vo);
        }
        return personalizedActivityDao.insertPersonalizedActivityVo(vo);
    }


}
